package com.szqhyxj.youxiangju.sys.components.view.popview;

import android.content.Context;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.szqhyxj.youxiangju.R;

import butterknife.OnClick;

/**
 * XiaoPanYu
 * on 2018/10/26
 */
public class SingleDialog extends BaseDialog {

    private LinearLayout album, takePhoto;
    private ImageView img;
    private ISharePlatformListener listener;


    public interface ISharePlatformListener {
        void sharePlatform(String platform);

        void onClickAlbum(View view);

        void onTakePhoto(View view);
    }

    public void setISharePlatformListener(ISharePlatformListener listener) {
        this.listener = listener;
    }

    public SingleDialog(Context context) {
        super(context);

        /** 放到setContentView 后设置才有效 设置dialog 宽 为 屏幕宽度 */
        WindowManager m = window.getWindowManager();
        Display d = m.getDefaultDisplay();
        WindowManager.LayoutParams p = window.getAttributes();
        p.width = d.getWidth(); //设置dialog的宽度为当前手机屏幕的宽度
        window.setAttributes(p);
        p.height = d.getHeight()/3;
        setGravity(Gravity.BOTTOM);
    }

    @Override
    public View initDialogView(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.popview_bottom, null);
        album = view.findViewById(R.id.album);
        takePhoto = view.findViewById(R.id.takePhoto);
        img = view.findViewById(R.id.top_view_right);
        album.setOnClickListener(this);
        takePhoto.setOnClickListener(this);
        img.setOnClickListener(this);
        return view;
    }


    public void setOnClickListener(ISharePlatformListener listener) {
        this.listener = listener;
    }
    @OnClick({R.id.album, R.id.takePhoto,R.id.top_view_right})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.album:
                if (listener != null) {
                    listener.onClickAlbum(view);
                }
                break;
            case R.id.takePhoto:
                if (listener !=null){
                    listener.onTakePhoto(view);
                }
                break;
            case R.id.top_view_right:
                dismiss();
                break;
        }
    }

}
